/******************************************************************************************************
Copyright (C) 2018 Mestrelab Research S.L. All rights reserved.

This file is part of the Mnova scripting toolkit.

Authorized users of MNova Software may use this file freely, but this file is provided AS IS
with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.
*****************************************************************************************************/

/*globals Dir, File*/
/*jslint plusplus: true, indent: 4, bitwise: true*/

if (!Dir.copy) {
	Dir.copy = function (aSrcDir, aDstDir) {
		"use strict";

		if (!aDstDir instanceof Dir || !aDstDir.exists || !aSrcDir instanceof Dir || !aSrcDir.exists) {
			return false;
		}

		var i, fileInfo,
			fileInfoList = aSrcDir.entryInfoList("*", Dir.All | Dir.Dirs | Dir.Drives | Dir.Executable | Dir.Files | Dir.Hidden | Dir.Modified | Dir.NoSymLinks | Dir.Readable | Dir.RWEMask | Dir.System | Dir.TypeMask | Dir.Writable | Dir.NoDotAndDotDot);

		for (i = 0; i < fileInfoList.length; i++) {
			fileInfo = fileInfoList[i];

			if (fileInfo.isFile) {
				File.copy(fileInfo.absoluteFilePath, aDstDir.filePath(fileInfo.fileName));
			} else if (fileInfo.isDir && fileInfo.fileName !== "." && fileInfo.fileName !== "..") {
				if (!aDstDir.mkdir(fileInfo.fileName)) {
					return false;
				}
				if (!Dir.copy(new Dir(aSrcDir.filePath(fileInfo.fileName)), new Dir(aDstDir.filePath(fileInfo.fileName)))) {
					return false;
				}
			}
		}

		return true;
	};

	Dir.alphanumericPathsCompare = function (aDir1, aDir2) {
		"use strict";

		return Dir._alphanumericPathsCompare(aDir1, aDir2);
	};
}
